/*   Copyright 2010 Jonathan Wagner
 *
 *   Licensed under the Apache License, Version 2.0 (the "License");
 *   you may not use this file except in compliance with the License.
 *   You may obtain a copy of the License at
 *
 *       http://www.apache.org/licenses/LICENSE-2.0
 *
 *   Unless required by applicable law or agreed to in writing, software
 *   distributed under the License is distributed on an "AS IS" BASIS,
 *   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *   See the License for the specific language governing permissions and
 *   limitations under the License.
 */
package com.alienos.collide;

import java.util.HashSet;
import java.util.Set;

import com.alienos.collide.bounds.BoundingVolume;
import com.google.common.collect.ImmutableSet;

/**
 * SpatialObject maintains internal collision references 
 * @author tigeba
 *
 * @param <I> Type info
 */
public final class SpatialObject<I> {

    private final I id;
    private final Set<I> activeCollisions;
    private final Transform transform;
    private final BoundingVolume bounds;

    public SpatialObject(I id, Transform transform, BoundingVolume bounds, Set<I> collisions) {
        this.transform = transform;
        this.id = id;
        this.bounds = bounds;
        // Dont collide with yourself
        if (collisions.contains(id)) {
            collisions = new HashSet<I>(collisions);
            collisions.remove(id);
        }
        this.activeCollisions = ImmutableSet.copyOf(collisions);
    }

    public Transform getTransform() {
        return transform;
    }

    public Set<I> getCollisions() {
        return activeCollisions;
    }

    public BoundingVolume getBounds() {
        return bounds;
    }

    public I getId() {
        return id;
    }

    @Override
    public String toString() {
        return "SpatialObject id=" + getId() + " activeCollisions=" + getCollisions();
    }

}